package com.hongxun.design.sqlite.popwind;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.hongxun.design.R;
import com.hongxun.design.mytools.IconSourse;
import com.hongxun.design.mytools.ToastShow;
import com.hongxun.design.ui.headandbottonpanel.HeadSecondControlPanel;
import com.hongxun.design.utils.DataUtil;

/**
 * Created by cqcqwu 创建项目模块
 */

public class ModularMaterialPW extends PopupWindow {
    private Handler handler;
    private Activity activity;

    /**
     * 0activity
     * 1handler
     */
    public ModularMaterialPW(Object... obj) {
        this.activity = (Activity) obj[0];
        this.handler = (Handler) obj[1];

        View view = LayoutInflater.from(activity).inflate(R.layout.pop_modularmaterial, null);
        ViewHolder holder = new ViewHolder(view);
        setContentView(view);
        setHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
        setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        setBackgroundDrawable(dw);
        setAnimationStyle(R.style.pop_ranim);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    class ViewHolder {
        EditText popFixEt1;
        EditText popFixEt2;

        HeadSecondControlPanel headsecond_layout;

        ViewHolder(View view) {
            popFixEt1 = (EditText) view.findViewById(R.id.pop_fix_et1);
            popFixEt2 = (EditText) view.findViewById(R.id.pop_fix_et2);

            headsecond_layout = (HeadSecondControlPanel) view.findViewById(R.id.setpoint_layout);
            headsecond_layout.initHeadPanel(DataUtil.getsecondbean("保存", View.VISIBLE, R.color.bar_right, null,
                    "创建项目模块", R.color.title, View.VISIBLE, IconSourse.BACK + "", View.VISIBLE));
            //返回
            headsecond_layout.mleftTitle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
            //保存
            headsecond_layout.setClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String name = String.valueOf(popFixEt1.getText()).trim();
                    String xhao = String.valueOf(popFixEt2.getText()).trim();
                    if (name.isEmpty()) {
                        ToastShow.showShort(activity, "名称不能为空");
                        return;
                    }

                    if (xhao.isEmpty()) {
                        ToastShow.showShort(activity, "型号不能为空");
                        return;
                    }
                    Bundle bundle = new Bundle();
                    bundle.putString("1", name);
                    bundle.putString("2", xhao);
                    Message message = handler.obtainMessage();
                    message.setData(bundle);
                    message.what = 1;
                    handler.sendMessage(message);
                    dismiss();
                }
            });
        }
    }
}
